var mysql = require('mysql');
var express = require('express');
var app = express();
var connection = mysql.createConnection({
  host: '127.0.0.1',
  port: '3306',
  user: 'root',
  password: 'admin',
  database: 'db_message'
})
// SELECT english 
// FROM `cet`
// WHERE english IN (SELECT english FROM tb_t)
connection.connect();
var getSql = 'SELECT * FROM tb_message';
var insertSql = ''
var str = '';
var str1 = '';
var impo = [];
connection.query(getSql, function (err, result) {
  if (err)
    console.log('SELECT ERROR:' + err);
  // console.log(result);
  //str = JSON.stringify(result);
  //impo = str1[0].content.split(" ");
  //console.log(impo);
  var str1 = result[0].content;
  str1 = str1.split(/\s+/);
  var str3 = [];
  str1.forEach(
    function (e) {
      var str2 = e.split(/([\.|\,|\'|\"|])/g);
      str2.forEach(w => {
        str3.push(w)
      })
    })
  str3 = str3.filter(item => item)
  console.log(str3);
  str3.forEach(function(word,index){
    var insertSql = "INSERT INTO tb_msg_word (id, english) VALUES ('" + index + "','" + word + "');"
    connection.query(insertSql, function (err, result) {
      if (err)
        console.log('INSERT ERROR:' + err);
      console.log(result);
    });
  })
});